#identify transit system by stop id
folder <- "K:\\Projects\\OrangeCoNC\\Features\\Ridership_Regression\\cleaned_data\\gtfs\\"
files <- list.files(paste0('K:\\Projects\\OrangeCoNC\\Features\\Ridership_Regression\\cleaned_data\\gtfs\\'),
recursive = T, full.names = F, pattern = "stops.txt")
read_stops <- function(x) {
read_csv(paste0(folder, x)) %>%
select(stop_id, stop_name) %>%
mutate(agency = str_remove(x, "/stops.txt"),
stop_id = as.character(stop_id))
}
stops_with_agency <- lapply(files, read_stops) %>%
bind_rows()
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_character(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## platform_code = col_logical(),
## stop_name = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_logical(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_character(),
## position = col_logical()
## )
##
## -- Column specification --------------------------------------------------------
## cols(
## stop_id = col_double(),
## stop_code = col_double(),
## stop_name = col_character(),
## stop_desc = col_character(),
## stop_lat = col_double(),
## stop_lon = col_double(),
## zone_id = col_logical(),
## stop_url = col_character(),
## location_type = col_double(),
## parent_station = col_logical(),
## stop_timezone = col_logical(),
## wheelchair_boarding = col_double()
## )
lines_with_attribues <- lines_with_attribues %>%
left_join(stops_with_agency, by = c("from_stop" = "stop_id"))
Map of Riders per Segment
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(lines_with_attribues) + tm_lines(col = "weighted_ridership", lwd = 2,
style = "fisher", n = 6, palette = "viridis")
PMT by Agency from Modeled Ridership
lines_with_attribues %>%
st_drop_geometry() %>%
group_by(agency) %>%
select(miles, pmt) %>%
summarise_all(sum, na.rm = T) %>%
mutate(total_pmt = sum(pmt),
portion_pmt = pmt / total_pmt) %>%
select(-total_pmt) %>%
kbl() %>%
kable_paper("hover", full_width = F)
## Adding missing grouping variables: `agency`
|
agency
|
miles
|
pmt
|
portion_pmt
|
|
chapel_hill_transit_gtfs_20190914
|
397.66586
|
64581.22
|
0.1659121
|
|
duke_gtfs_20190830
|
79.04083
|
18259.29
|
0.0469090
|
|
gocary_gtfs_20190420
|
71.56329
|
14993.06
|
0.0385179
|
|
godurham_gtfs_20190914
|
570.47683
|
64491.34
|
0.1656812
|
|
goraleigh_gtfs_20190907
|
558.69939
|
96130.35
|
0.2469633
|
|
gotriangle_gtfs_20190907
|
1281.12799
|
58727.85
|
0.1508746
|
|
ncsu_wolfline_gtfs_20190826
|
84.90499
|
42556.12
|
0.1093286
|
|
part_gtfs_08122020
|
680.22882
|
29510.30
|
0.0758133
|
NTD Ridership
read_csv("K:\\Projects\\OrangeCoNC\\Features\\Ridership_Regression\\cleaned_data\\model_inputs\\ntd_ridership.csv") %>%
select(-GTFS_Route_Type) %>%
mutate(total_ridership = sum(Annual_Ridership),
portion_ridership = Annual_Ridership / total_ridership) %>%
select(-total_ridership) %>%
kbl() %>%
kable_paper("hover", full_width = F)
##
## -- Column specification --------------------------------------------------------
## cols(
## Agency = col_character(),
## GTFS_Route_Type = col_double(),
## Annual_Ridership = col_double()
## )
|
Agency
|
Annual_Ridership
|
portion_ridership
|
|
chapelhilltransit
|
6523418
|
0.2243702
|
|
duke
|
4995203
|
0.1718079
|
|
gocary
|
209563
|
0.0072078
|
|
godurham
|
6715030
|
0.2309606
|
|
goraleigh
|
5049379
|
0.1736713
|
|
gotriangle
|
1636072
|
0.0562720
|
|
ncsuwolfline
|
3506210
|
0.1205946
|
|
part
|
439476
|
0.0151156
|